import { getAllAppList,selectAppList } from '@/api/configs/appConfig.js'

export default {
  data () {
    return {
      productList: [],
      channelList: [],
      productListNew:[]
    }
  },
  created () {
    this.getProductList();
  },
  methods: {
    getProductList () {
      getAllAppList().then(response => {
        this.productList = response.data.map(item => {
          return {
            name: item.appname,
            value: item.appcode,
            channelList: item.channelList
          }
        })
        this.productListNew = response.data.map(item => {
          return {
            name: item.appname,
            value: item.appcode
          }
        })
      })
    },
    _productChange () {
      this.form.channel = ''
      this._getChannelList()
    },
    _getChannelList () {
      let vm = this
      let currItem = vm.productList.filter(item => {
        return item.value === vm.form.appcode
      })[0]
      vm.form.appname = currItem.name
      vm.channelList = currItem.channelList.map(item => {
        return {
          name: item.channel,
          value: item.channel,
          innerList: item.innerList,
          outList: item.outList
        }
      })
    },
    _changeAppType () {
      this.form.key = '';
    },
    _configKeyChange (form) {
      let vm = this
      let keyConfig = {
        0: 'INNER_CONFIG_KEY',
        1: 'OUT_CONFIG_KEY',
      }
      let currItem = vm.dict.type[keyConfig[form.type]].filter(item => {
        return item.value === vm.form.key
      })[0]
      vm.form.name = currItem.label
      if("app_ad_config"===currItem.value){
        vm.form.textarea = '{"ad_switch":"0","nature_ad_switch":"0","privacy_switch":"1"}'
      }else if("app_pass_back_config"===currItem.value){
        vm.form.textarea = '[{"eventCode":"event_1","etp":1,"code":"","num":0,"hr":168,"pkg":"","openDeduction":false,"ipu":1,"accountId":"","deduction":"1000100000","ecpm":300,"arpu":2500,"open":true,"cvr":0},{"eventCode":"event_2","etp":1,"code":"","num":0,"hr":168,"pkg":"","openDeduction":false,"ipu":1,"accountId":"","deduction":"1000100000","ecpm":300,"arpu":2500,"open":true,"cvr":0},{"eventCode":"event_3","etp":1,"code":"","num":0,"hr":168,"pkg":"","openDeduction":false,"ipu":1,"accountId":"","deduction":"1000100000","ecpm":500,"arpu":3500,"open":true,"cvr":0}]'
      }else if("app_batch_pass_back_config"===currItem.value){
        if("huawei"===form.channel){
          vm.form.textarea = '[{"eventCode":"event_1","accountId":"","maxEcpm":800,"minArpu":500,"maxArpu":2500,"minEcpm":100,"open":true},{"eventCode":"event_2","accountId":"","maxEcpm":800,"minArpu":500,"maxArpu":2500,"minEcpm":100,"open":true},{"eventCode":"event_3","accountId":"","maxEcpm":800,"minArpu":500,"maxArpu":2500,"minEcpm":100,"open":true}]'
        }else if("oppo"===form.channel){
          vm.form.textarea = '[{"eventCode":"event_1","accountId":"","minEcpm":100,"maxEcpm":500,"minArpu":1000,"maxArpu":2000,"deductionRate":1,"open":true},{"eventCode":"event_2","accountId":"","minEcpm":300,"maxEcpm":800,"minArpu":2000,"maxArpu":3500,"deductionRate":1,"open":true},{"eventCode":"event_3","accountId":"","minEcpm":300,"maxEcpm":800,"minArpu":3000,"maxArpu":5000,"deductionRate":1,"open":true}]'
        }else if("yingyongbao"===form.channel){
          vm.form.textarea = '[{"eventCode":"event_1","accountId":"","minCost":50,"minEcpm":100,"minIpu":5,"roiRatio":"1.1","billingRatio":"1.1","open":true},{"eventCode":"event_4","accountId":"","minCost":50,"minEcpm":100,"minIpu":5,"roiRatio":"1.1","billingRatio":"1.1","open":true}]'
        }
      }else{
        vm.form.textarea = '{}'
      }
    }
  },
}
